package com.test.io.basic;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @author rgsmaster
 * @date 2024/7/23 9:51
 * @description
 */
public class Client {

    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("localhost", 8565);
        System.out.println("已经连击刀服务器");


        // 获取输入输出流
        PrintWriter printWriter = new PrintWriter(socket.getOutputStream(), true);
        // 向服务器发送信息
        printWriter.println("你好，服务器");

        // 读取服务器回复的信息
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line = bufferedReader.readLine();
        System.out.println("服务器回复的信息：" + line);

        // 关闭资源
        bufferedReader.close();
        printWriter.close();
        socket.close();
    }
}
